package org.wattdepot.cli.commands;

import org.junit.Test;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;

/**
 * This class tests the sensor day command of the 
 * CommandLineInterface's actual commands.
 * @author David Mau
 */
public class TestCommandSensorDay {
  
  /**
   * Tests the normal operation of the sensor day command.
   */
  @Test
  public void testSensorDayStamp() {
    // Create a new sensor day command object.
    SensorDayCommand command = new SensorDayCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "SIM_KAHE_2", "2009-10-31" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Ready the output that we know is true
    String knownOutput = "2009-10-31T00:00:00.000-10:00  ";
    knownOutput = knownOutput.concat("Tool: OscarDataConverter  ");
    knownOutput = knownOutput.concat("Properties: (powerGenerated : 5.5E7)");

    // Compare the two to see if they are the same enough.
    assertTrue("Checking known data's first row.", sourceOutput.contains(knownOutput));
    
    knownOutput = "2009-10-31T23:45:00.000-10:00  ";
    knownOutput = knownOutput.concat("Tool: OscarDataConverter  ");
    knownOutput = knownOutput.concat("Properties: (powerGenerated : 5.7E7)");
    
    // Compare the two to see if they are the same enough.
    assertTrue("Checking known data's last row.", sourceOutput.contains(knownOutput));
  }

  /**
   * Test bad time stamp detection for the sensor day command.
   */
  @Test
  public void testSensorBadTime() {
    // Create a new sensor time stamp command object.
    SensorDayCommand command = new SensorDayCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "SIM_KAHE_2", "OOGA BOOGA" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Check to see if the correct error returned
    assertTrue("Checking for correct response to bad timestamp", sourceOutput
        .contains(WattDepotCliCommand.badTimeStamp));
  }

  /**
   * Test bad source detection for the sensor day command.
   */
  @Test
  public void testSensorBadSource() {
    // Create a new sensor day command object.
    SensorDayCommand command = new SensorDayCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList( "BLAH", "2009-10-31" );
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Check to see if the right error returned.
    assertTrue("Checking for correct response to bad source", sourceOutput
        .contains(WattDepotCliCommand.resourceNotFound));
  }
  
  /**
   * Tests to see if the sensor day command can handle excess arguments.
   */
  @Test
  public void testExcessArguments() {
    // Create a new sensor day command object.
    SensorDayCommand command = new SensorDayCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1", "2", "3");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking excess SensorTimeStamp argument handling", 
        sourceOutput.contains(WattDepotCliCommand.tooManyArguments));
  }
  
  /**
   * Tests to see if the sensor day command can handle not enough arguments.
   */
  @Test
  public void testFewArguments() {
    // Create a new sensor day command object.
    SensorDayCommand command = new SensorDayCommand(null);
    // Create a new List to store the args
    List<String> args = Arrays.asList("1");
    
    // Get the output from the command
    String sourceOutput = command.doCommand( args );

    // Make sure that the command is returning the error properly
    assertTrue("Checking SensorTimeStamp handling not enough arguments", 
        sourceOutput.contains(WattDepotCliCommand.missingArguments));
  }
}
